# !/usr/bin/env python3
# -*- coding:utf-8 -*-
# author: 廖择贵
# createTime: 2021-03-02 21:53

import requests
from comment.logger_handle import LoggerHandler

logger = LoggerHandler("Requests_Handler")


class Requests_Handler(object):

    def __init__(self):
        self.session = requests.Session()

    def do_request(self, url, method, params=None, data=None, json=None, **kwargs):
        """
        请求方法：method
        请求参数：params, data, json,
        其他头信息等：**kwargs
        """
        logger.debug("开始发送请求，接口地址:\n %s ; \n请求参数：\n params=%s,data=%s,json=%s"
                     % (url, params, data, json))

        res = self.session.request(method=method, url=url, params=params, data=data, json=json, **kwargs)
        if json is not None:
            return res.json()
        return res.text

    def close_session(self):
        self.session.close()




